package top.sjydzq.www.controller.Management;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import top.sjydzq.www.service.NoticeService;

@Controller
@RequestMapping("/management/notice/")
public class MNoticeController {
    @Autowired
    private NoticeService noticeService;

    @RequestMapping("list")
    public String list(Model model) {
        model.addAttribute("notices", noticeService.selectAll());

        return "Management/Notice/list";
    }

    @RequestMapping("add")
    public String add() {
        return "Management/Notice/add";
    }
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public String handleAdd(String title, String content) {
        if (noticeService.add(title, content)) {
            return "redirect:/management/notice/list";
        } else {
            return "redirect:/management/notice/add";
        }
    }

    @RequestMapping("remove")
    public String handleRemove(int id) {
        noticeService.remove(id);

        return "redirect:/management/notice/list";
    }
}
